package com.sample.springbootsample.controller;


import com.alibaba.fastjson.JSONObject;
import com.sample.springbootsample.random.JsonObject;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SsoLoginController {


    @RequestMapping(value = "/grant",method = {RequestMethod.POST,RequestMethod.GET})
    public String grantUrl(@RequestBody JSONObject reqObj){
        //JSONObject reqObj = JSONObject.parseObject(req);
        JSONObject jsonObject = new JSONObject();
        if ("adam".equals(reqObj.get("clientId"))){
            jsonObject.put("code","codeSuccess");
        }
        return jsonObject.toJSONString();
    }

    @RequestMapping(value = "/token",method = {RequestMethod.POST,RequestMethod.GET})
    public String token(@RequestBody JSONObject reqObj){
        JSONObject jsonObject = new JSONObject();
        if ("codeSuccess".equals(reqObj.get("grantCode"))){
            jsonObject.put("access_token","tokenSuccess");
        }
        return jsonObject.toJSONString();
    }


    @RequestMapping(value = "/userInfo",method = {RequestMethod.POST,RequestMethod.GET})
    public String getUserInfo(@RequestBody JSONObject reqObj){
        JSONObject jsonObject = new JSONObject();
        if ("tokenSuccess".equals(reqObj.get("access_token"))){
            jsonObject.put("userId","admin");
        }
        return jsonObject.toJSONString();
    }
}
